<?php
/**
 * lay bo loc theo gia voi cate_id
 * @param int $cate_id
 * @return array $header, $rs, $pager
 * @author anhmantk
 * @date Dec 30, 2011
 */
function getAllFilterPrice($cate_id) {
    $header = array(
        array('data' => 'STT', 'width' => '30'),
        array('data' => 'Tên hiển thị', 'field' => 'cprice_name', 'sort' => 'asc'),        
        array('data' => 'Giá'),
        array('data' => 'Trạng thái', 'width' => '100'),
        array('data' => 'Sửa', 'width' => '30'),
        array('data' => 'Khóa', 'width' => '45')
    );
    
    $where = "cate_id = " . $cate_id;
    $query = "SELECT * FROM {category_filter_price} WHERE " . $where . " " . tablesort_sql($header);
    $count_query = "SELECT COUNT(cprice_id) FROM {category_filter_price} WHERE " . $where;
    $result = pager_query($query, LIMIT_PAGER, 0, $count_query);
    
    while(($obj = db_fetch_object($result)) != null) {       
        $rs[] = $obj;
    }
    
    $pager = theme('pager');
    return array($header, $rs, $pager);
}

/**
 * lay lai thong tin filter price theo id
 * @param int $cprice_id
 * @return stdClass thong tin filter price
 * @author anhmantk
 * @date Dec 30, 2011
 */
function getFilterPrice($cprice_id) {
    $query = "SELECT * FROM {category_filter_price} WHERE cprice_id = %d";
    return db_fetch_object(db_query($query, $cprice_id));
}

/**
 * them moi filter price
 * @param array $params 
 * array(`cate_id`, `cprice_name`, `cprice_min`, `cprice_max`, `cprice_status`)
 * @return boolean
 * @author anhmantk
 * @date Dec 30, 2011
 */
function insertFilterPrice($params = array()) {
    $query = "INSERT INTO {category_filter_price} (`cate_id`, `cprice_name`, `cprice_min`, `cprice_max`, `cprice_status`) VALUES (%d, '%s', %d, %d, %d)";
    return db_query($query, $params);
}

/**
 * sua thong tin filter price
 * @param array $params
 *  array(`cprice_name`, `cprice_min`, `cprice_max`, `cprice_status`, `cprice_id`)
 * @return boolean 
 * @author anhmantk
 * @date Dec 30, 2011
 */
function editFilterPrice($params = array()) {
    $query = "UPDATE {category_filter_price} SET `cprice_name` = '%s', `cprice_min` = %d, `cprice_max` = %d, `cprice_status` = %d WHERE cprice_id = %d";
    return db_query($query, $params);
}

/**
 * khoa hoac bo khoa filter price
 * @param int $status
 * @param int $cprice_id
 * @return boolean
 * @author anhmantk
 * @date Dec 30, 2011
 */
function lockUnlockFilterPrice($status  = 0,$cprice_id) {
    $query = "UPDATE {category_filter_price} SET cprice_status = %d WHERE cprice_id = %d";
    return db_query($query, array($status, $cprice_id));
}